package com.evan.idempotent.autoconfigure;

import com.evan.idempotent.aspect.DistributedIdempotentAspect;
import com.evan.idempotent.idempotent.DistributedIdempotent;
import com.evan.idempotent.properties.IdempotentProperties;
import com.evan.idempotent.storage.IdempotentStorageFactory;
import com.evan.idempotent.storage.idempotentstorageimpl.IdempotentStorageMysql;
import com.evan.idempotent.storage.idempotentstorageimpl.IdempotentStorageRedis;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @Description: 幂等功能（注解）接口注入Bean
 * @Author liudeguang
 */
@Configuration
@EnableConfigurationProperties({IdempotentProperties.class})
@AutoConfigureAfter({DistributedLockAutoConfiguration.class, IdempotentAutoConfiguration.class})
public class IdempotentAspectAutoConfiguration {

    @Resource
    private DistributedIdempotent distributedIdempotent;

    @Bean
    public DistributedIdempotentAspect distributedIdempotentAspect() {
        return new DistributedIdempotentAspect(distributedIdempotent);
    }

    @Bean
    public IdempotentStorageFactory idempotentStorageFactory() {
        return new IdempotentStorageFactory();
    }

    @Bean
    public IdempotentStorageRedis idempotentStorageRedis() {
        return new IdempotentStorageRedis();
    }

    @Bean
    public IdempotentStorageMysql idempotentStorageMysql() {
        return new IdempotentStorageMysql();
    }
}
